package com.jiamao.goplay.util;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.jiamao.goplay.base.BaseMVCActivity;

public class KeyInputUtils {


    public static void ShowKeyboard(View v)
    {
        InputMethodManager imm = ( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );

      //  imm.showSoftInput(v,InputMethodManager.SHOW_FORCED);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }


    public static  void showInputMethodWindow(final EditText editContent) {

        InputMethodManager im = (InputMethodManager) editContent
                .getContext().getSystemService(
                        Context.INPUT_METHOD_SERVICE);
        im.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

    }

    public static void hideInputMethodWindow(final EditText editContent) {

        InputMethodManager im = (InputMethodManager) editContent
                .getContext().getSystemService(
                        Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(editContent.getWindowToken(), 0);

    }

    protected static void hideInput(Activity activity) {

        InputMethodManager im = (InputMethodManager)activity. getSystemService(Context.INPUT_METHOD_SERVICE);
        if (im != null && activity.getCurrentFocus() != null) {
            im.hideSoftInputFromWindow(activity.getCurrentFocus()
                            .getApplicationWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }

    }

    public static void hideSoftInputView(Activity activity) {

        // TODO Auto-generated method stub
        InputMethodManager manager = ((InputMethodManager) activity
                .getSystemService(Activity.INPUT_METHOD_SERVICE));
        if (activity.getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (activity.getCurrentFocus() != null)
                manager.hideSoftInputFromWindow(activity.getCurrentFocus()
                                .getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
        }

    }
}
